package com.tj.shopping.web.controller;

import com.tj.shopping.service.IAdminService;
import com.tj.shopping.service.IGoodstypeService;
import com.tj.shopping.service.impl.AdminServiceImpl;
import com.tj.shopping.service.impl.GoodstypeServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

@WebServlet("/type")
public class GoodstypeController extends BaseController{
    private IGoodstypeService service = new GoodstypeServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        String op = req.getParameter("op");
        if ("findall".equals(op)){
            doFindall(req,resp);
        } else {
            resp.getWriter().print("no such Method....");
        }
    }

    private void doFindall(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        Map<String,Object> m = service.findall();
        printToJson(resp,m);//响应给页面的是m
    }
}
